
$(document).ready(function(){
	var value;
//	点击按钮
	$(".a",this).click(function(){
		value=$(this).parent('td').parent('tr').find('td').eq(0).html();
		v1=$(this).parent('td').parent('tr').find('td').eq(1).html();
		v2=$(this).parent('td').parent('tr').find('td').eq(2).html();
		v3=$(this).parent('td').parent('tr').find('td').eq(3).html();
		v4=$(this).parent('td').parent('tr').find('td').eq(4).html();
		$("#ads_name").attr("value",v1);
		$("#ads_sex").attr("value",v2);
		$("#ads_phone").attr("value",v3);
		$("#ads_detail").attr("value",v4);
		
	}); 
//	确认修改
	$(".b",this).click(function(){
		var data1={
				ads_name:$("#ads_name").val(),
				ads_sex:$("#ads_sex").val(),
				ads_detail:$("#ads_detail").val(),
				ads_phone:$("#ads_phone").val(),
				ads_default:$("#ads_default").val(),
				ads_id:value
		};
		$.ajax({
			type:"POST",
			data:data1,
			url :'updateAddress.do',
			error : function(request) {
				alert("请求异常!!!");
			},
			success : function(data) {
				alert(data);
				$(myModal_edit).modal('hide');
				window.location.reload();
			}
		});
	}); 
	$(".default",this).click(function(){
		if(confirm("设为默认地址？")){
			address_id=$(this).parent('td').parent('tr').find('td').eq(0).html();
			var data3={
					
					c_id:$("#c_id").val(),
					address_id:address_id
			};
			$.ajax({
				type:"POST",
				data:data3,
				url :'updateDefault.do',
				error : function(request) {
					alert("请求异常!!!");
				},
				success : function(data) {
					window.location.reload();
				}
			});
		}
		
	}); 
	$(".del",this).click(function(){
		if(confirm("删除这条地址？"))
			{
			address_id=$(this).parent('td').parent('tr').find('td').eq(0).html();
			var data4={
					address_id:address_id
			};
			$.ajax({
				type:"POST",
				data:data4,
				url :'delAddress.do',
				error : function(request) {
					alert("请求异常!!!");
				},
				success : function(data) {
					alert(data);
					window.location.reload();
				}
			});
			}
		
	}); 
	$(".delCustom",this).click(function(){
		if(confirm("确认删除此用户？"))
			{
			c_id=$(this).parent('td').parent('tr').find('td').eq(0).html();
			var data4={
					c_id:c_id
			};
			$.ajax({
				type:"POST",
				data:data4,
				url :'delCustom.do',
				error : function(request) {
					alert("请求异常!!!");
				},
				success : function(data) {
					alert(data);
					window.location.reload();
				}
			});
			}
		
	}); 
	$(".edit_nick",this).click(function(){
		var data6={
				c_nick:$("#c_nick").val(),
				c_id:$("#c_id").val()
		};
		$.ajax({
			type:"POST",
			data:data6,
			url :'editNick.do',
			error : function(request) {
				alert("请求异常!!!");
			},
			success : function(data) {
				alert(data);
				window.location.reload();
			}
		});
	}); 


});
window.addEventListener('load',function(){

	//code是后台传入的验证字符串
	var code = "jsaidaisd656",
	codeFn = new moveCode(code);

//	获取当前的code值
//	console.log(codeFn.getCode());
	//改变code值
	//code = '46asd546as5';
	//codeFn.setCode(code);

	//重置为初始状态
	//codeFn.resetCode();
});
function compare(){
	var a = document.getElementById('c_pwd').value;
	var b = document.getElementById('c_r_pwd').value;

	if (a == b) {
		document.getElementById('ts').innerHTML = "";
		return true;
	} else {
		document.getElementById('ts').innerHTML = "两次密码输入不一致！";
		return false;
	}


} 
function yanzhengpwd(){
	var pwd=document.getElementById('pwd').value;//数据库密码
	var password = document.getElementById('inputpwd').value;//输入原密码
	var password1 = document.getElementById('inputpwd1').value;//输入新密码
	var password2 = document.getElementById('inputpwd2').value;
	if(pwd!=password){
		return false;
	}
	else{
		if(password1!=password2){
			return false;
		}
		else{
			return true;
		}
	}
}

function repwd(){
	var c_id=document.getElementById('c_id').value;//id
	var password = document.getElementById('inputpwd1').value;//输入原密码
	var data5={
		c_pwd:password,
		c_id:c_id
	}
	if(yanzhengpwd()){ 
		$.ajax({
			url : "repwd.do",
			type : "post",
			data : data5,
			async : false,
			cache : false,
			error : function(request) {
				alert("请求异常!!!");
			},
			success : function(data) {
				
				alert(data);
				window.location.reload();
			}
		});
	}
	else{
		alert("未通过验证，请检查");
	}
}
function yanzheng(){
	var a = document.getElementById('c_pwd').value;
	var b = document.getElementById('c_name').value;
	if(a!=""&&b!="")
	{
		return true;
	}
	else
	{
		return false;
	}
}
function login(){
	var arry1={};
	arry1.name=$("#name").val();
	arry1.pwd=$("#pwd").val();
	$.ajax({
		url : 'loginJudgement.do',
		type : "post",
		data : arry1,
		async : false,
		cache : false,
		error : function(request) {
			alert("请求异常!!!");
		},
		success : function(data) {
			if(data!=0){
				alert("登陆成功");
				$(myModal22).modal('hide');
			}
			else{
				alert("账号或密码错误");
				document.getElementById("pwd").value="";
			}

		}
	});
}
function login_admin() {
	var data66={
			admin_name:$("#admin_name").val(),
			admin_pwd:$("#admin_pwd").val()
	}
	$.ajax({
		url : 'login_admin.do',
		type : "post",
		data : data66,
		async : false,
		cache : false,
		error : function(request) {
			alert("请求异常!!!");
		},
		success : function(data) {
			if(data!=0){
				
				alert("商家登陆成功");
				window.location.href="indexback.jsp";
			}
			else{
				alert("账号或密码错误");
			}
		}
	});
}
function ads_yanzheng(){
	address_name=$("#address_name").val(),
	address_detail=$("#address_detail").val(),
	address_phone=$("#address_phone").val()
	if(address_name!=""&&address_detail!=""&&address_phone!=""){
		return true;
	}else{
		return false; 
	}
}
function add_ads(){
	var data2={
			address_name:$("#address_name").val(),
			address_sex:$("#address_sex").val(),
			address_detail:$("#address_detail").val(),
			address_phone:$("#address_phone").val(),
			address_default:$("#address_default").val(),
			c_id:$("#c_id").val()
	};
	if(ads_yanzheng()){
		$.ajax({
			type:"POST",
			data:data2,
			url :'insertAddress.do',
			error : function(request) {
				alert("请求异常!!!");
			},
			success : function(data) {
				alert(data);
				window.location.reload();
				$(myModal_add).modal('hide');
				
			}
		});
	}
	else{
		alert("带*项不能为空！");
	}
	
}

function length() {
	var b = document.getElementById('c_name').value.length;
	if(b<4||b>12){
		return false;
	}
	else{
		return true;
	}
}
function regist(){
	if(length()){
		if(compare()){
			if(yanzheng()){
				var arry={};
				arry.c_name=$("#c_name").val();
				arry.c_pwd=$("#c_pwd").val();
				$.ajax({
					url : "addCustom.do",
					type : "post",
					data : arry,
					async : false,
					cache : false,
					error : function(request) {
						alert("请求异常!!!");
					},
					success : function(data) {
						alert(data);
						$(myModal3).modal('hide');
					}
				});
			}
			else{
				alert("账号密码不能为空");
			}
		}
		else{
			alert("两次密码不一致");
			document.getElementById("c_pwd").value="";
			document.getElementById("c_r_pwd").value="";
		}
	}
	else{
		alert("账号长度4~12位\n      ( ͡° ͜ʖ ͡°)");
		document.getElementById("c_name").value="";
		document.getElementById("c_pwd").value="";
		document.getElementById("c_r_pwd").value="";
	}
	



} ;



//$(".editAds1",this).click(function(){

//}); 




